from constants.agent import AGENT
from constants.glove import GLOVES
from constants.rifle import RIFLE
from constants.pistol import PISTOL
from constants.knives import KNIVES
import pydash


ACCESSORIES = GLOVES + RIFLE + PISTOL + KNIVES + AGENT


# 获取所需要的参数
def parse_params(tags=[], wears=["FN"], extra={}):
    # 过滤标签
    filter_list = (
        list(
            filter(lambda x: len(pydash.difference(tags, x["tags"])) == 0, ACCESSORIES)
        )
        if len(tags) > 0
        else ACCESSORIES
    )
    # 格式化参数
    result_list = []
    for item in filter_list:
        params = {
            "def_index": item["def_index"],
            "paint_index": item.get("paint_index", None),
            **extra,
        }
        # 原皮
        if "VANILLA" in item.get("tags", []):
            params_with_wear = {
                **params,
                "category": "1",
                "item_name": f'{item["item_name"]}',
                "min_price": "0",
                "max_price": "10000000",
            }
            result_list.append(params_with_wear)
        elif "AGENT" in item.get("tags", []):
            params_with_wear = {
                **params,
                "item_name": f'{item["item_name"]}',
                "min_price": "0",
                "max_price": "10000000",
            }
            result_list.append(params_with_wear)
        else:
            # 崭新出厂
            if "FN" in wears:
                if not item.get("NO_FN", False):
                    params_with_wear = {
                        **params,
                        "category": "1",
                        "item_name": f'{item["item_name"]} (Factory New)',
                        "max_float": "0.07",
                    }
                    result_list.append(params_with_wear)
            # 略有磨损
            if "MW" in wears:
                if not item.get("NO_MW", False):
                    params_with_wear = {
                        **params,
                        "category": "1",
                        "item_name": f'{item["item_name"]} (Minimal Wear)',
                        "min_float": "0.07",
                        "max_float": "0.15",
                    }
                    result_list.append(params_with_wear)
            # 久经沙场
            if "FT" in wears:
                if not item.get("NO_FT", False):
                    params_with_wear = {
                        **params,
                        "category": "1",
                        "item_name": f'{item["item_name"]} (Field-Tested)',
                        "min_float": "0.15",
                        "max_float": "0.38",
                    }
                    result_list.append(params_with_wear)
            # 破损不堪
            if "WW" in wears:
                if not item.get("NO_WW", False):
                    params_with_wear = {
                        **params,
                        "category": "1",
                        "item_name": f'{item["item_name"]} (Well-Worn)',
                        "min_float": "0.38",
                        "max_float": "0.45",
                    }
                    result_list.append(params_with_wear)
            # 战痕累累
            if "BS" in wears:
                if not item.get("NO_BS", False):
                    params_with_wear = {
                        **params,
                        "category": "1",
                        "item_name": f'{item["item_name"]} (Battle-Scarred)',
                        "min_float": "0.45",
                    }
                    result_list.append(params_with_wear)
    return result_list
